package com.sicau.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sicau.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sicau.common.annotation.Log;
import com.sicau.common.core.controller.BaseController;
import com.sicau.common.core.domain.AjaxResult;
import com.sicau.common.enums.BusinessType;
import com.sicau.system.domain.BShare;
import com.sicau.system.service.IBShareService;
import com.sicau.common.utils.poi.ExcelUtil;
import com.sicau.common.core.page.TableDataInfo;

/**
 * 运动分享Controller
 * 
 * @author ruoyi
 * @date 2022-03-19
 */
@RestController
@RequestMapping("/system/share")
public class BShareController extends BaseController
{
    @Autowired
    private IBShareService bShareService;

    /**
     * 查询运动分享列表
     */
    @PreAuthorize("@ss.hasPermi('system:share:list')")
    @GetMapping("/list")
    public TableDataInfo list(BShare bShare)
    {
        startPage();
        List<BShare> list = bShareService.selectBShareList(bShare);
        return getDataTable(list);
    }

    /**
     * 导出运动分享列表
     */
    @PreAuthorize("@ss.hasPermi('system:share:export')")
    @Log(title = "运动分享", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BShare bShare)
    {
        List<BShare> list = bShareService.selectBShareList(bShare);
        ExcelUtil<BShare> util = new ExcelUtil<BShare>(BShare.class);
        util.exportExcel(response, list, "运动分享数据");
    }

    /**
     * 获取运动分享详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:share:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bShareService.selectBShareById(id));
    }

    /**
     * 新增运动分享
     */
    @PreAuthorize("@ss.hasPermi('system:share:add')")
    @Log(title = "运动分享", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BShare bShare)
    {
        bShare.setCreateBy(SecurityUtils.getUsername());
        return toAjax(bShareService.insertBShare(bShare));
    }

    /**
     * 修改运动分享
     */
    @PreAuthorize("@ss.hasPermi('system:share:edit')")
    @Log(title = "运动分享", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BShare bShare)
    {
        bShare.setCreateBy(SecurityUtils.getUsername());
        return toAjax(bShareService.updateBShare(bShare));
    }

    /**
     * 删除运动分享
     */
    @PreAuthorize("@ss.hasPermi('system:share:remove')")
    @Log(title = "运动分享", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bShareService.deleteBShareByIds(ids));
    }
}
